// import React from "react";
// import { Switch, Route ,Redirect} from "react-router-dom"
// import Login from "./pages/Login/Login"
// import Register from "./pages/Register/Register"
// import Index from "./pages/Index/Index"
// import List from "./pages/List/List"
// import Home from "./pages/Home/Home"
// import Goods from "./pages/Goods/Goods"

// function App() {
//   return (
//     <div >
//       <Switch>
//         <Route path="/login" component={Login}></Route>
//         <Route path="/register" component={Register}></Route>
//         <Route path="/index" component={Index}></Route>
//         <Route path="/list" component={List}></Route>
//         <Route path="/home" component={Home}></Route>
//         <Route path="/goods/:id/:type" component={Goods}></Route>
//         <Redirect to="/login"></Redirect>
//       </Switch>
//     </div>
//   );
// }

// export default App;

import React, { useReducer } from 'react';
import { Switch, Route, Redirect } from "react-router-dom"
import { DotLoading } from "antd-mobile"
import PrivateRoute from './utils/PrivateRoute';
import { initState, reducer } from './reducer/app';
const Index = React.lazy(() => import("./pages/Index/Index"))
const Register = React.lazy(() => import("./pages/Register/Register"))
const List = React.lazy(() => import("./pages/List/List"))
// const Search = React.lazy(() => import("./pages/Search/Search"))
const Detail = React.lazy(() => import("./pages/Goods/Goods"))
const Login = React.lazy(() => import("./pages/Login/Login"))
//创建上下文
export const MyContext = React.createContext()
const App = () => {
  const [state, dispatch] = useReducer(reducer, initState)
  return (
    <div className='app'>
      {/* 传递数据  */}
      <MyContext.Provider value={ {state,dispatch} }>
        <React.Suspense fallback={<DotLoading color='primary' />}>
          {/* Switch 路由视图 */}
          <Switch>
            {/* Route 路由规则 */}
            <Route path="/login" component={Login}></Route>
            <Route path="/register" component={Register}></Route>
            <PrivateRoute path="/index" component={Index}></PrivateRoute>
            <PrivateRoute path="/list" component={List}></PrivateRoute>
            {/* <Route path="/list" component={List}></Route>
           <Redirect to="/login"></Redirect>
          */}
            <PrivateRoute path="/detail/:id/:type" component={Detail}></PrivateRoute>
            {/* <PrivateRoute path="/search" component={Search}></PrivateRoute> */}
            {/* Redirect 重定向 */}
            <Redirect to="/login"></Redirect>
          </Switch>
        </React.Suspense>
      </MyContext.Provider>
    </div>
  );
}

export default App;

